//所有商品展示的服务
package org.csu.wuliu.service;

import org.csu.wuliu.domain.Category;
import org.csu.wuliu.domain.Item;
import org.csu.wuliu.domain.Product;
import org.csu.wuliu.persistence.CategoryMapper;
import org.csu.wuliu.persistence.ItemMapper;
import org.csu.wuliu.persistence.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatalogService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ItemMapper itemMapper;


    //category相关
    public Category getCategory(String categoryId){
        return categoryMapper.getCategory(categoryId);
    }

    public List<Category> getCategoryList(){
        return categoryMapper.getCategoryList();
    }

    public boolean isCategoryIdExist(String categoryId){
        if(getCategory(categoryId)==null){
            return false;
        }
        else return true;
    }

    //更新
    public void updateCategory(Category category){
        categoryMapper.updateCategory(category);
    }

//    public void updateCategoryDescribes(String categoryId,String describes){
//        categoryMapper.updateCategoryDescribes(categoryId,describes);
//    }

    public void insertCategory(Category category){
        categoryMapper.insertCategory(category);
    }

    public void deleteCategory(String categoryId){
        categoryMapper.deleteCategory(categoryId);
    }

    //product相关
    public List<Product> getProductListByCategory(String categoryId){
        return productMapper.getProductListByCategory(categoryId);
    }

    public Product getProduct(String productId){
        return productMapper.getProduct(productId);
    }

    public boolean isProductIdExist(String productId){
        if(getProduct(productId)==null){
            return false;
        }
        else return true;
    }

    public List<Product> searchProductList(String keyword){
        return productMapper.searchProductList("%" + keyword.toLowerCase() + "%");
    }

    public void insertProduct(Product product){
        productMapper.insertProduct(product);
    }

    public void deleteProduct(String productId){
        productMapper.deleteProduct(productId);
    }

    public void updateProduct(Product product){
        productMapper.updateProduct(product);
    }




    //Item相关
    public Item getItem(String itemId){
        return itemMapper.getItem(itemId);
    }

    public boolean isItemIdExist(String itemId){
        if(getItem(itemId)==null){
            return false;
        }
        else return true;
    }

    public List<Item> getItemListByProduct(String productId){
        return itemMapper.getItemListByProduct(productId);
    }

    public void insertItem(Item item){
        itemMapper.insertItem(item);
    }



    public void updateItem(Item item){
        itemMapper.updateItem(item);
    }

    public void deleteItem(String itemId){
        itemMapper.deleteItem(itemId);
    }

    //wnx增加
    public List<Item> getAllItems(){
        return itemMapper.getAllItems();
    }

}
